import { Button, DatePicker, Tooltip } from 'antd';
import { PlusCircleOutlined, DeleteOutlined, AppstoreAddOutlined } from '@ant-design/icons';
import { onMouseOutBtn, removeDateHmsStr, renderTableText, tableSorter } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { DictionaryRenderFun, formatDecimal, formatDecimalFour } from '../../Acommon';

/** 资产表格 */
const openAssetColumns = (delSelectRow, openAssetModalStatus, pageType?: string) => {
  let tableConfig: Record<string, any>[] = [
    {
      title: '资产编号',
      dataIndex: 'assetCode',
      key: 'assetCode',
      width: 160,
      fixed: 'left',
      visible: true,
      sorter: (a: any, b: any) => (a.assetCode > b.assetCode ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '资产名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 160,
      fixed: 'left',
      ellipsis: {
        showTitle: true,
      },
      visible: true,
      unDrag: true,
      sorter: (a: any, b: any) => (a.assetName > b.assetName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '资产分类',
      dataIndex: 'assetClassName',
      key: 'assetClassName',
      width: 120,
      ellipsis: {
        showTitle: true,
      },
      visible: true,
      unDrag: true,
      sorter: (a: any, b: any) => (a.assetClassName > b.assetClassName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '品牌',
      dataIndex: 'brandType',
      key: 'brandType',
      width: 120,
      visible: true,
      sorter: (a: any, b: any) => (a.brandType > b.brandType ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '规格型号',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      width: 170,
      visible: true,
      sorter: (a: any, b: any) => (a.paramsInfo > b.paramsInfo ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '数量',
      dataIndex: 'quantityOrArea',
      key: 'quantityOrArea',
      width: 100,
      visible: true,
      sorter: (a: any, b: any) => (a.quantityOrArea > b.quantityOrArea ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text === 0 || text ? text : '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '计量单位',
      dataIndex: 'unitOfMeasurementName',
      key: 'unitOfMeasurementName',
      width: 110,
      visible: true,
      sorter: (a: any, b: any) => (a.unitOfMeasurementName > b.unitOfMeasurementName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '资产原值（元）',
      dataIndex: 'totalValue',
      key: 'totalValue',
      width: 170,
      visible: true,
      sorter: (a: any, b: any) => (a.totalValue > b.totalValue ? 1 : -1),
      render: (text: number | null) => formatDecimalFour(text),
    },
    // {
    //   title: '管理部门',
    //   dataIndex: 'assetDepartmentName',
    //   key: 'assetDepartmentName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.useDepartmentName > b.useDepartmentName ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '管理人',
    //   dataIndex: 'asseterName',
    //   key: 'asseterName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.userName > b.userName ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    {
      title: '使用部门',
      dataIndex: 'useDepartmentName',
      key: 'useDepartmentName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.useDepartmentName > b.useDepartmentName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '使用人',
      dataIndex: 'userName',
      key: 'userName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.userName > b.userName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '存放区域',
      dataIndex: 'locationName',
      key: 'locationName',
      width: 110,
      visible: true,
      sorter: (a: any, b: any) => (a.locationName > b.locationName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    // {
    //   title: '详细地点',
    //   dataIndex: 'locationInfo',
    //   key: 'locationInfo',
    //   width: 180,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.locationInfo > b.locationInfo ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '取得方式',
    //   dataIndex: 'obtainTypeName',
    //   key: 'obtainTypeName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.obtainTypeName > b.obtainTypeName ? 1 : -1),
    //   render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    // },
    // {
    //   title: '取得日期',
    //   dataIndex: 'obtainDate',
    //   key: 'obtainDate',
    //   width: 200,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.obtainDate > b.obtainDate ? 1 : -1),
    //   render: (text: string) => removeDateHmsStr(text) || '--',
    // },
    // {
    //   title: '合同编号',
    //   dataIndex: 'contractCode',
    //   key: 'contractCode',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.contractCode > b.contractCode ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '财务入账状态',
    //   dataIndex: 'entryStateName',
    //   key: 'entryStateName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.entryStateName > b.entryStateName ? 1 : -1),
    //   render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    // },
  ];
  if (pageType != 'detail') {
    tableConfig?.push({
      title: (
        <div style={{ width: '100%', textAlign: 'center' }}>
          <Button
            type="link"
            size="small"
            icon={<AppstoreAddOutlined />}
            className="manageBtntTxtStyle"
            onMouseOut={onMouseOutBtn}
            onClick={openAssetModalStatus}
          >
            选择
          </Button>
        </div>
      ),
      dataIndex: 'otherBtn',
      key: 'otherBtn',
      visible: true,
      width: 100,
      fixed: 'right',
      render: (_text: any, record: any) => {
        return (
          <div className="counterpoartDelBtnStyle">
            <Button
              type="link"
              size="small"
              icon={<DeleteOutlined />}
              className={'manageBtntTxtStyle'}
              onMouseOut={onMouseOutBtn}
              onClick={() => delSelectRow(record)}
            >
              删除
            </Button>
          </div>
        );
      },
    });
  }
  return tableConfig;
};

/** 表格配置 */
const assetTableConfig = () => {
  return [
    {
      title: '资产编号',
      dataIndex: 'assetCode',
      key: 'assetCode',
      width: 160,
      fixed: 'left',
      visible: true,
      sorter: (a: any, b: any) => (a.assetCode > b.assetCode ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '资产名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 120,
      fixed: 'left',
      ellipsis: {
        showTitle: true,
      },
      visible: true,
      unDrag: true,
      sorter: (a: any, b: any) => (a.assetName > b.assetName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '资产分类',
      dataIndex: 'assetClassName',
      key: 'assetClassName',
      width: 120,
      ellipsis: {
        showTitle: true,
      },
      visible: true,
      unDrag: true,
      sorter: (a: any, b: any) => (a.assetClassName > b.assetClassName ? 1 : -1),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '品牌',
      dataIndex: 'brandType',
      key: 'brandType',
      width: 120,
      visible: true,
      sorter: (a: any, b: any) => (a.brandType > b.brandType ? 1 : -1),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '规格型号',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      width: 170,
      visible: true,
      sorter: (a: any, b: any) => (a.paramsInfo > b.paramsInfo ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '状态',
      dataIndex: 'assetStateName',
      key: 'assetStateName',
      width: 110,
      visible: true,
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetStateName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '所属仓库',
      dataIndex: 'assetStoreName',
      key: 'assetStoreName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetStoreName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '数量',
      dataIndex: 'quantityOrArea',
      key: 'quantityOrArea',
      width: 100,
      visible: true,
      sorter: (a: any, b: any) => (a.quantityOrArea > b.quantityOrArea ? 1 : -1),
      render: (text: number | null) => formatDecimal(text),
    },
    {
      title: '计量单位',
      dataIndex: 'unitOfMeasurementName',
      key: 'unitOfMeasurementName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.unitOfMeasurementName > b.unitOfMeasurementName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '资产原值（元）',
      dataIndex: 'totalValue',
      key: 'totalValue',
      width: 170,
      visible: true,
      sorter: (a: any, b: any) => (a.totalValue > b.totalValue ? 1 : -1),
      render: (text: number | null) => formatDecimalFour(text),
    },
    // {
    //   title: '管理部门',
    //   dataIndex: 'assetDepartmentName',
    //   key: 'assetDepartmentName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.useDepartmentName > b.useDepartmentName ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '管理人',
    //   dataIndex: 'asseterName',
    //   key: 'asseterName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.userName > b.userName ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    {
      title: '使用部门',
      dataIndex: 'useDepartmentName',
      key: 'useDepartmentName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.useDepartmentName > b.useDepartmentName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '使用人',
      dataIndex: 'userName',
      key: 'userName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.userName > b.userName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '存放区域',
      dataIndex: 'locationName',
      key: 'locationName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.locationName > b.locationName ? 1 : -1),
      render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '详细地点',
      dataIndex: 'locationInfo',
      key: 'locationInfo',
      width: 180,
      visible: true,
      sorter: (a: any, b: any) => (a.locationInfo > b.locationInfo ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    // {
    //   title: '取得方式',
    //   dataIndex: 'obtainTypeName',
    //   key: 'obtainTypeName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.obtainTypeName > b.obtainTypeName ? 1 : -1),
    //   render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    // },
    // {
    //   title: '取得日期',
    //   dataIndex: 'obtainDate',
    //   key: 'obtainDate',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.obtainDate > b.obtainDate ? 1 : -1),
    //   render: (text: string) => removeDateHmsStr(text) || '--',
    // },
    // {
    //   title: '合同编号',
    //   dataIndex: 'contractCode',
    //   key: 'contractCode',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.contractCode > b.contractCode ? 1 : -1),
    //   render: (text: string) => {
    //     return (
    //       <Tooltip title={text}>
    //         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '财务入账状态',
    //   dataIndex: 'entryStateName',
    //   key: 'entryStateName',
    //   width: 150,
    //   visible: true,
    //   sorter: (a: any, b: any) => (a.entryStateName > b.entryStateName ? 1 : -1),
    //   render: (text: number | null) => DictionaryRenderFun({ text, isState: false }),
    // },
  ];
};

export { openAssetColumns, assetTableConfig };
